package com.huang.A01_case;

import java.util.Random;

/**
 * 目标：
 * 完成生成随机验证码的案例
 */
public class Demo2 {
    public static void main(String[] args) {
        System.out.println(createCode(4));
    }
    public static String createCode(int n){
        //for循环 生成几位随机数
        Random r = new Random();
        String code = "";
        for (int i = 1; i <= n; i++) {
            //随机0：数字 1：大写字母 2：小写字母
            int num = r.nextInt(3);
            switch (num){
                case 0:
                    code += r.nextInt(10);
                    break;
                case 1:
                    //大写字母 65  65+25   0-25
                    char c = (char) (r.nextInt(26) + 65);
                    code += c;
                    break;
                case 2:
                    //小写字母 97 97+25 0-25
                    char c1 = (char) (r.nextInt(26) + 97);
                    code += c1;
                    break;
            }
        }
        return  code;
    }
}